using System;

using Pegasus.Diagnostics;

namespace Pegasus.UnitTests.Workflow.Service.Workflows
{
	/// <summary>
	/// Workflow that test the data exchange events
	/// </summary>
	public class TestStartupWorkflow : Pegasus.Workflow.Service.Workflow
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="T:TestStartupWorkflow"/> class.
		/// </summary>
		public TestStartupWorkflow() :
			base( "TestEventWorkflow" )
		{
		}

		/// <summary>
		/// Sets the startup args for the workflow.
		/// </summary>
		/// <param name="args">The args.</param>
		/// <remarks>
		/// This method is called prior to the workflow begin registered with the
		/// persistence service and entering into it's initial state.  This is called
		/// sync as part of the workflow startup process.  So the workflow ID has
		/// not been assigned at the point where this method is called.
		/// If you throw an exception the workflow startup process will be halted
		/// and the worklfow will not be created.
		/// </remarks>
		public override void SetStartupArgs( object[] args )
		{
			base.SetStartupArgs( args );

			// Some test will pass in bad params just to ensure that the start
			// process handles exception in the proper maner.
			
			// Check Parameters
			ParamCode.AssertNotNull( args, "args" );
			ParamCode.Assert( args.Length == 2, "args", "Wrong number of args" );
			ParamCode.Assert( args[ 0 ] is int, "args[ 0 ]", "Wrong type for argument 0" );
			ParamCode.Assert( args[ 1 ] is string, "args[ 1 ]", "Wrong type for argument 1" );

			base.SetStartupArgs( args );
		}

		/// <summary>
		/// Registers the states.
		/// </summary>
		public override void RegisterStates()
		{
			StateStartAndEnd initState = new StateStartAndEnd();
		
			RegisterState( initState );

			SetInitialState( initState.Name );
		}
	}
}
